package com.zjsru.oneDay;

/**
 * 一年中的第几天
 *
 *
 * 输入：date = "2019-01-09"
 * 输出：9
 * */

public class dayofyear {
    public int dayOfYear(String date) {
        int year = Integer.parseInt(date.substring(0, 4));
        int month = Integer.parseInt(date.substring(5, 7));
        int day = Integer.parseInt(date.substring(8));

        int[] amount = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
//        考虑闰年
        if(year%400 ==0 || ( year %4==0 && year%100 != 0)){
                ++amount[1];
        }

        int ans = 0;
        for (int i = 0; i < month-1; i++) {
            ans += amount[i];
        }
        return ans + day;
    }
    public static void main(String[] args){
        dayofyear dayofyear = new dayofyear();
        int result = dayofyear.dayOfYear("2019-01-19");
        System.out.println(result);
    }
}
